<?php

/**
 * RaiseTestFirstRun class
 * The UI to load when the path to phpRaise Raise.php file is not defined yet
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @final
 * @package Raise.UnitTest
 * @version 1.4
 */
final class RaiseTestFirstRun {

    public static function run(){
        if($_POST && array_key_exists('l', $_POST)){
            $path = str_replace(array('\'', '<', '>', "\n", "\r", "\t"), '', $_POST['l']);
            if(strtolower(pathinfo($path, PATHINFO_BASENAME)) == 'raise.php'){
                file_put_contents(RAISE_INCLUDE, $path);
            }
            header('Location: index.php');
            exit;
        }
        
        $version = file_get_contents('VERSION');

        $outputBuffer .= '<!DOCTYPE html>
            <html><head><title>Welcome to RaiseTestPanel v' . $version . '</title>' . self::cssCode() . '</head>';
        $outputBuffer .= '<body><div class="container"><div class="header">RaiseTestPanel v' . $version . '<div class="sub">Automated Testing for <a href="http://code.google.com/p/phpraise" target="_blank">phpRaise</a> by <a href="http://twitter.com/thephpdeveloper" target="_blank">Sam-Mauris Yong</a><br />Source code under <a href="http://www.gnu.org/licenses/gpl.html" target="_blank">GNU General Public License v3</a></div></div><div class="entries">';

        $outputBuffer .= '<div class="header">Welcome</div>' . '<div class="entry_message">
                <p>Welcome to phpRaise Automated Unit Testing Tool</p>
            </div><div class="header">Configuration</div>' . '<div class="entry_message">
                <p>RaiseTestPanel needs to know the <b class="tooltip" title="Location, see http://en.wikipedia.org/wiki/Ten-code">10-20</b> of phpRaise framework that you are using. </p>
                <form action="index.php" method="post" target="_top" style="margin: 50px;">
                    <label for="loc">Pathname to <b class="tooltip" title="Raise.php is the entry point of the framework, normally found in the root folder of the framework.">Raise.php</b>:</label>
                    <input type="text" id="loc" name="l" value="" /><input type="submit" value="Go" />
                </form>
                <p>Note that you must include the Raise.php filename inside the pathname. If you move the framework folder often, you can try using relative pathname instead of absolute so as to minimize configuration. </p>
                <p>RaiseTestPanel will be shown once the path to phpRaise framework is known and this message will be vapourised. To re-configure RaiseTestPanel, simply delete the ' . RAISE_INCLUDE . ' file in the testing tool directory and you will see this message again.</p>
            </div>';

        $outputBuffer .= '</div></div></body></html>';
        echo $outputBuffer;
    }

    /**
     * Return the CSS code
     * @return string
     * @static
     */
    private static function cssCode(){
        return '<style type="text/css"><!--
            body{font:normal 12px/1.6 Tahoma}a:visited,a{font-family:Lucida Sans;text-decoration:none;color:#EB0}a:hover{text-decoration:underline;color:#FC3}.container{width:630px;margin:20px auto 100px}.header{font:bold 25px Lucida Sans;margin-bottom:10px;color:#666;height:90px}.header,.header .sub{margin-left:10px}.header .sub{font:normal 11px/2.2 Verdana;margin-top:5px;color:#AAA;border-left:5px solid #EEE;background:#f6f6f6;margin-right:30px}.header .sub,.entries .header{padding-left:10px}.entries,.entries .sysinfo .info:hover{background:#EEE}.entries,.entries .sysinfo,.entries .sysinfo .info,.entries .header,.entries .summary,#ftr{padding:5px}.entries,.entries .sysinfo .info{clear:both}.entries .resultset{text-shadow:1px 1px 3px #555}.entries .sysinfo{width:600px;margin:5px auto;background:#FFF}.entries .sysinfo .info{text-align:right;border-bottom:1px solid #EEE}.entries .sysinfo .info .label{float:left;color:#888}.entries .header{font:16px Tahoma;color:#222;height:auto}.entries .name{font:18px Tahoma}.entries .entry_warning,.entries .entry_message,.entries .entry_error,.entries .final{padding:5px 10px}.entries .entry_warning,.entries .entry_message,.entries .entry_error{margin:5px 20px;border-left:5px solid #CCC}.entries .entry_error{background:#A00}.entries .entry_error,.entries .entry_message,.entries .entry_warning,.entries .summary{color:#FFF}.entries .entry_message{background:#999}.entries .entry_warning{background:#EA1}.entries .summary{margin:5px;background:#666}.entries .final{color:#333;text-shadow:1px 1px 0 #FFF}#ftr{border:5px solid #EEE}#abtLink,#abtCloseLink{display:none}#abtCloseLink{float:right;}b.tooltip{font-weight:normal;cursor:help; border-bottom:1px dashed #CCC;}
            --></style>';
    }
    
}
